//
//  LoginViewModel.swift
//  SouWeiLaiSwift
//
//  Created by yxl on 2022/4/22.
//

import Foundation
import HandyJSON

protocol LoginRequestDelegate: NSObjectProtocol{
    // 登录成功回调
    func loginFinishSuccess (loginModel : LoginModel)
}


class LoginViewModel : NSObject{
    weak var delegate: LoginRequestDelegate?
    // 登录请求
    func requestLogin(pwd:String,mobile:String){
        HttpTool.request(LoginAPI.login(pwd: (pwd as String), mobile: (mobile as String))) {[weak self] dic in
            let model = JSONDeserializer<LoginModel>.deserializeFrom(dict: (dic as! NSDictionary))
            UserManager.sharedManager.saveUserModel(userModel: model!)
            self?.delegate?.loginFinishSuccess(loginModel: model!)
        } failure: { code, msg in
            
        }
    }
}
